"""mxonline URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.urls import path, include, re_path
from django.views.generic import TemplateView
import xadmin

from users.views import LoginView, RegisterView, ActiveView, ForgerPwdView, \
    ResetView, ModifyPwdView, LogoutView, IndexView

from .settings import MEDIA_ROOT
from django.views.static import serve

urlpatterns = [
    path('xadmin/', xadmin.site.urls),
    # path('', TemplateView.as_view(template_name="index.html"), name="index"),
    path('', IndexView.as_view(), name="index"),
    path('login/', LoginView.as_view(), name="login"),
    path('logout/', LogoutView.as_view(), name="logout"),
    path('register/', RegisterView.as_view(), name="register"),
    path('forget/', ForgerPwdView.as_view(), name="forget_pwd"),
    path('modify_pwd/', ModifyPwdView.as_view(), name="modify_pwd"),
    path('captcha/', include('captcha.urls')),
    re_path('^active/(?P<token>.*)$', ActiveView.as_view(), name='active'),  # 用户激活
    re_path('^reset/(?P<token>.*)$', ResetView.as_view(), name='reset'),  # 用户重置

    # 课程机构url配置
    path('org/', include(('organization.urls', 'organization'), namespace='org')),

    # 课程机构url配置
    path('courses/', include(('courses.urls', 'courses'), namespace='courses')),

    # 个人中心url配置
    path('users/', include(('users.urls', 'users'), namespace='users')),

    re_path(r'^media/(?P<path>.*)$', serve, {'document_root': MEDIA_ROOT}),

    # re_path('^static/(?P<path>.*)$', serve, {'document_root': STATIC_ROOT}),

    re_path(r'^ueditor/', include('DjangoUeditor.urls')),
]

# 全局404页面配置
handler404 = 'users.views.page_not_found'
handler500 = 'users.views.page_error'
